﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Read.API.Application.Commends.Productionorderss;
using MyMES.Read.API.Dtos;
using System;

namespace MyMES.Read.API.Application.CommendHandlers.Productionorderss
{
    public class GetWorkoperateCommendHandlers : IRequestHandler<GetWorkoperateCommends, APIPaging<List<woekderProess>>>
    {

        private readonly IBaseRepository<woekderProess> workorderRepository;
        private readonly IMapper mapper;

        public GetWorkoperateCommendHandlers(IBaseRepository<woekderProess> workorderRepository, IMapper mapper)
        {
            this.workorderRepository = workorderRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 获取操作记录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIPaging<List<woekderProess>>> Handle(GetWorkoperateCommends request, CancellationToken cancellationToken)
        {
            APIPaging<List<woekderProess>> result = new APIPaging<List<woekderProess>>();
            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            string sql = "select * from woekderproess";


            var list =await workorderRepository.SelectAsync(sql);

            result.TotalCount = list.Count;
            result.TotalPage = (int)Math.Ceiling(result.TotalCount * 1.0 / request.PageSize);
            list = list.Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize).ToList();

            result.data = list;
            return  result;
        }
    }
}
